<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jstl/fmt" %>
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %>
<%@ page contentType = "text/html; charset=UTF-8" %>

<html>
<head>

<c:set var="cssFileName">
	<c:out value="${crudViewMeta.cssFileName}" default="default.css"/>
</c:set>
<link rel="stylesheet" href="<c:url value='/css/${cssFileName}'/>" type="text/css">

<title><c:out value="${crudMeta.title}"/>文本导入页面</title>

<script type="text/javascript">

function gotoListView()
{
	window.location="<c:url value='/list.do'><c:param name='name' value='${crudMeta.beanName}'/>
	<c:forEach items='${crudMeta.otherWantedParameters}' var='wantedParam'>
    	<c:param name='${wantedParam}' value='${param[wantedParam]}'/>
    </c:forEach></c:url>";
}

<!--提交删除一批记录-->
function submitDataImportForm()
{    
	if( dataImportForm.fileFieldId.value  == '' )
	{
		alert("请指定上传文件!");
		return false;
	}

	dataImportForm.submit();
}

</script>

</head>

<body>

<!--统计文本解析未通过的行数-->
<c:set var="parseErrorIndex" value="0"/>
<c:forEach items="${command.records}" var="item" varStatus="s">
	<spring:bind path="command.records[${s.index}].originalStr">
		<c:if test="${not empty status.errorMessage}">
			<c:set var="parseErrorIndex"><c:out value="${parseErrorIndex + 1}"/></c:set>
		</c:if>
	</spring:bind>
</c:forEach>

<!--统计校验没有通过的字段数-->
<c:set var="validateErrorIndex" value="0"/>
<c:forEach items="${command.records}" var="item" varStatus="s">
	<spring:bind path="command.records[${s.index}].recordCommand.*">
		<c:if test="${not empty status.errorMessage}">
			<c:set var="validateErrorIndex"><c:out value="${validateErrorIndex + 1}"/></c:set>
		</c:if>
	</spring:bind>
</c:forEach>

<table class="top" align="center">
	<tr><td class="headtitle"><c:out value="${crudMeta.title}"/>文本导入</td></tr>
</table>

<form name="dataImportForm" action="<c:url value='/dataImportForm.do'/>" method="POST"  encType="multipart/form-data">

	<input type="hidden" name="name" value="<c:out value='${crudMeta.beanName}'/>"/>
	<c:forEach items="${crudMeta.otherWantedParameters}" var="wantedParam">
		<input type="hidden" name="<c:out value='${wantedParam}'/>" value="<c:out value='${param[wantedParam]}'/>">
	</c:forEach>
	
	<table class="content">
    	<tr class="body">
      		<td class="head">上传文件:</td>
      		<td> 
      			<spring:bind path="command.file"> 
        			<input type=file id="fileFieldId" name="<c:out value="${status.expression}"/>" value="<c:out value='${status.value}'/>">
          		</spring:bind>
      		</td>
    	</tr>  
	</table>
	
	<br>
	
	<!--生成上传提示信息-->
	<table>
		<tr><td><b>上传注意事项：</b></td></tr>
		<tr><td><span class="hint">->&nbsp;&nbsp;上传文本期望的分隔符为：<c:out value="${importMeta.delimiter}"/></span></td></tr>
		<tr><td><span class="hint">->&nbsp;&nbsp;上传文本期望的列的依次顺序为：
			<c:forEach items="${importMeta.columnNames}" var="colName">
				<c:forEach items="${crudMeta.columnMetas}" var="col">
		  			<c:if test="${colName == col.colName}"><c:out value="${col.title}"/>&nbsp;&nbsp;</c:if>
		  		</c:forEach>
			</c:forEach>
		</span></td></tr>
		<c:forEach items="${crudMeta.columnMetas}" var="col">
			<c:if test="${not empty col.hint}">
				<tr>
					<td><span class="hint">->&nbsp;&nbsp;列[<c:out value='${col.title}'/>]：<c:out value="${col.hint}"/></span><td>
				</tr>
			</c:if>
	</c:forEach>
	</table>
	
  	<br>
  	<c:if test="${parseErrorIndex > 0}">
  		<c:set var="parseErrorIndex" value="0"/>
		<table width="100%">
			<c:forEach items="${command.records}" var="item" varStatus="s">
				<spring:bind path="command.records[${s.index}].originalStr">
					<c:if test="${not empty status.errorMessage}">
						<tr><span class="validateError">
							<c:out value="${parseErrorIndex+1}"/>.&nbsp;&nbsp;<c:out value="${status.errorMessage}"/>
						</span></tr>
						<c:set var="parseErrorIndex"><c:out value="${parseErrorIndex + 1}"/></c:set>
					</c:if>
				</spring:bind>
			</c:forEach>
		</table>
	</c:if>
	
	<c:if test="${validateErrorIndex > 0}">
		<c:set var="validateErrorIndex" value="0"/>
		<table width="100%">
			<c:forEach items="${command.records}" var="item" varStatus="s">
				<c:forEach items="${crudMeta.columnMetas}" var="col">
				<c:if test="${not empty command.records[s.index].recordCommand}">
				<spring:bind path="command.records[${s.index}].recordCommand.mapContent[${col.colName}]">
					<c:if test="${not empty status.errorMessage}">
						<tr><span class="validateError">
							<c:out value="${validateErrorIndex+parseErrorIndex+1}"/>.&nbsp;&nbsp;第<c:out value="${s.index+1}"/>行、列[<c:out value='${col.title}'/>]：
							<c:out value="${status.errorMessage}"/>
						</span></tr>
						<c:set var="validateErrorIndex"><c:out value="${validateErrorIndex + 1}"/></c:set>
					</c:if>
				</spring:bind>
				</c:if>
				</c:forEach>
			</c:forEach>
		</table>
		<br>
	</c:if>

	<table>
		<tr align="center" valign="center">
			<td align="left" width="50%">
				<input type="button" name="upload" value="导入文本" onclick="javascript:submitDataImportForm()">
				<input type="button" name="back" value="返回" onclick="javascript:gotoListView()">
			</td>
			<td width="50%">
			</td>
		</tr>
	</table>

</form>

</body>
</html>